package com.ist.viewpagerhelper.activity.loop;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.ist.viewpagerhelper.ContractUtils;
import com.ist.viewpagerhelper.GlideManager;
import com.ist.viewpagerhelper.R;
import com.ist.viewpagerhelper.bean.ViewPagerBean;
import com.ist.viewpagerhelper.indicator.ZoomIndicator;
import com.ist.viewpagerhelper.view.BannerViewPager;
import com.ist.viewpagerhelper.indicator.TransIndicator;

import java.util.ArrayList;
import java.util.List;

public class LoopActivity extends AppCompatActivity {


    private static final Integer[] RES = {R.mipmap.guide1,R.mipmap.guide2,R.mipmap.guide3,
            R.mipmap.guide4 };

    private static final String[] RESURL = {
            "http://img.mukewang.com/54bf7e1f000109c506000338-590-330.jpg",
            "http://upload.techweb.com.cn/2015/0114/1421211858103.jpg",
            "http://img1.cache.netease.com/catchpic/A/A0/A0153E1AEDA115EAE7061A0C7EBB69D2.jpg",
            "http://image.tianjimedia.com/uploadImages/2015/202/27/57RF8ZHG8A4T_5020a2a4697650b89" +
                    "c394237ba9ffbb45fe8555a2cbec-6O6nmI_fw658.jpg"};
    private BannerViewPager mBannerCountViewPager;
    private BannerViewPager mBannerCountViewPager2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loop);


        // 获取view的值
        List<View> views = new ArrayList<>();

        for (int i = 0; i < RESURL.length; i++) {
            ImageView imageView = new ImageView(this);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            new GlideManager.Builder()
                    .setContext(this)
                    .setTargetSource(RESURL[i])
                    .setImageView(imageView)
                    .setLoadingBitmap(R.mipmap.ic_launcher )
                    .builder();
            views.add(imageView);
        }


        // 第一个viewpager
        mBannerCountViewPager = (BannerViewPager) findViewById(R.id.loop_viewpager);
        ZoomIndicator scaleIndicator = (ZoomIndicator) findViewById(R.id.bottom_scale_layout);

        ViewPagerBean bean =  new ViewPagerBean.Builder()
                .setViewPager(mBannerCountViewPager)
                .setIndicator(scaleIndicator)
                .setDataObjects(RESURL)
                .setDataCount(RESURL.length)
                .setMode(ContractUtils.LOOP_MAX_MODE)
                .builder();
        mBannerCountViewPager.setViewPagerBean(bean);


        mBannerCountViewPager2 = (BannerViewPager) findViewById(R.id.loop_viewpager2);
        TransIndicator transIndicator = (TransIndicator) findViewById(R.id.bottom_trans_layout);
        // 第二个轮播图
        ViewPagerBean bean2 =  new ViewPagerBean.Builder()
                .setViewPager(mBannerCountViewPager2)
                .setDataObjects(RES)
                .setDataCount(RES.length)
                .setIndicator(transIndicator)
                .setMode(ContractUtils.LOOP_MAX_MODE)
                .builder();
        mBannerCountViewPager2.setViewPagerBean(bean2);



    }

    @Override
    protected void onPause() {
        super.onPause();
        mBannerCountViewPager.onPause();
        mBannerCountViewPager2.onPause();


    }

    @Override
    protected void onResume() {
        super.onResume();
        mBannerCountViewPager.onReusme();
        mBannerCountViewPager2.onReusme();
    }
}
